﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Chefbook.DataObjects;
using System.Globalization;
using Chefbook.ViewModels;

namespace Chefbook.UserActions
{
    /// <summary>
    /// An action to create a new recipe
    /// </summary>
    public class CreateRecipeAction : UserActionBase
    {
        private CategoryViewModel parent;
        private RecipeViewModel recipe;

        /// <summary>
        /// Creates a new action to create a new recipe
        /// </summary>
        /// <param name="parent">The parent of the recipe to create</param>
        public CreateRecipeAction(CategoryViewModel parent)
            : base()
        {
            this.parent = parent;
        }

        /// <summary>
        /// Creates a new recipe
        /// </summary>
        public override void DoAction()
        {
            base.DoAction();
            recipe = new RecipeViewModel(new Recipe(parent.CategoryModel));
        }

        /// <summary>
        /// Deletes the created recipe
        /// </summary>
        public override void UndoAction()
        {
            base.UndoAction();
            recipe.RecipeModel.Delete();
        }

        /// <summary>
        /// Returns a user-friendly string describing the action
        /// </summary>
        /// <returns>A user-friendly string describing the action</returns>
        public override string ToString()
        {
            return string.Format(CultureInfo.CurrentUICulture, "Create new Recipe in Category '{0}'", parent);
        }
    }
}
